(function (window) {
	'use strict';
	var list_json = localStorage.getItem('list') || '[]';
	var list = JSON.parse(list_json);
	var id = list.length ;
	var first = true;
	var app = new Vue({
		el: '#app',
		data: {
			writeInput: '',
			list: list || []
		},
		computed: {
			isDoneAmount() {
				//遍历list,找到总共isDone的数量
				let amount = 0;
				this.list.forEach((item, i) => {
					if (item.isDone == false) {
						amount++
					}
				})
				return amount;
			}
		},
		methods: {
			getInput() {
				if (this.writeInput == '') {
					return
				}
				if (first) {
					list.forEach((element, index) => {
						element.id = index;
					});
					first = false;
				}
				this.list.push({
					id: id++,
					title: this.writeInput,
					//默认显示
					isDone: false
				});

				//设置localStorage
				localStorage.setItem('list', JSON.stringify(this.list));
				this.writeInput = '';
			},
			del(id) {
				this.list.forEach((element, i) => {
					if (element.id == id) {
						this.list.splice(i, 1)
						return true;
					}
				});
				localStorage.setItem('list', JSON.stringify(this.list));
			},
			showAmount() {
				//遍历list,找到总共isDone的数量
				let amount = 0;
				this.list.forEach((item, i) => {
					if (item.isDone == false) {
						amount++
					}
				})
				return amount;
			},
			setItem() {
				localStorage.setItem('list', JSON.stringify(this.list));
			}
		}
	})


})(window);